package lib

import (
	"fmt"
	"math/rand"
	"strconv"

	"github.com/PuerkitoBio/goquery"
)

var lists = map[string]string{
	"性感美女":        "https://www.mzitu.com/tag/xinggan/",
	"诱惑":          "https://www.mzitu.com/tag/youhuo/",
	"熟女少妇":        "https://www.mzitu.com/tag/shunvshaofu/",
	"制服诱惑":        "https://www.mzitu.com/tag/zhifu/",
	"睡衣诱惑":        "https://www.mzitu.com/tag/shuiyiyouhuo/",
	"性感内衣":        "https://www.mzitu.com/tag/xingganneiyi/",
	"前凸后翘":        "https://www.mzitu.com/tag/tuigirl/",
	"爆乳":          "https://www.mzitu.com/tag/baoru/",
	"情趣SM":        "https://www.mzitu.com/tag/sm/",
	"美女走光":        "https://www.mzitu.com/tag/zouguang/",
	"美臀翘臀":        "https://www.mzitu.com/tag/meitun/",
	"湿身诱惑":        "https://www.mzitu.com/tag/shishen/",
	"小清新":         "https://www.mzitu.com/tag/qingxin/",
	"清纯美女":        "https://www.mzitu.com/tag/qingchun/",
	"校花":          "https://www.mzitu.com/tag/xiaohua/",
	"美腿":          "https://www.mzitu.com/tag/leg/",
	"甜美女孩":        "https://www.mzitu.com/tag/tianmei/",
	"黑丝":          "https://www.mzitu.com/tag/heisi/",
	"比基尼":         "https://www.mzitu.com/tag/bikini/",
	"姐妹花":         "https://www.mzitu.com/tag/jiemeihua/",
	"齐B小短裙":       "https://www.mzitu.com/tag/duanqun/",
	"丝袜":          "https://www.mzitu.com/tag/siwa/",
	"网袜":          "https://www.mzitu.com/tag/wangwa/",
	"护士":          "https://www.mzitu.com/tag/hushi/",
	"OL诱惑":        "https://www.mzitu.com/tag/ol/",
	"萝莉":          "https://www.mzitu.com/tag/luoli/",
	"混血美女":        "https://www.mzitu.com/tag/hunxue/",
	"旗袍":          "https://www.mzitu.com/tag/qipao/",
	"车模":          "https://www.mzitu.com/tag/chemo/",
	"空姐":          "https://www.mzitu.com/tag/kongjie/",
	"热裤":          "https://www.mzitu.com/tag/reku/",
	"COSPLAY":     "https://www.mzitu.com/tag/cosplay/",
	"夏茉GIGI":      "https://www.mzitu.com/tag/xiamo-gigi/",
	"于大小姐":        "https://www.mzitu.com/tag/yudaxiaojie/",
	"顾欣怡":         "https://www.mzitu.com/tag/guxinyi/",
	"南湘baby":      "https://www.mzitu.com/tag/nanxiang-baby/",
	"娜依灵儿":        "https://www.mzitu.com/tag/nayilinger/",
	"刘飞儿":         "https://www.mzitu.com/tag/liufeier/",
	"朱可儿":         "https://www.mzitu.com/tag/barbie-ker/",
	"潘娇娇":         "https://www.mzitu.com/tag/panjiaojiao/",
	"杉原杏璃":        "https://www.mzitu.com/tag/sanyuanxingli/",
	"toro羽住":      "https://www.mzitu.com/tag/toro-yuzhu/",
	"王馨瑶":         "https://www.mzitu.com/tag/wangxinyao/",
	"黄可christine": "https://www.mzitu.com/tag/huangke/",
	"许诺sabrina":   "https://www.mzitu.com/tag/xunuo/",
	"夏瑶baby":      "https://www.mzitu.com/tag/xiayao-baby/",
	"原干惠":         "https://www.mzitu.com/tag/yuanganhui/",
	"今野杏南":        "https://www.mzitu.com/tag/jinyexingnan/",
	"森下悠里":        "https://www.mzitu.com/tag/shenxiayouli/",
	"绮里嘉ula":      "https://www.mzitu.com/tag/qilijia/",
	"玛鲁娜manuela":  "https://www.mzitu.com/tag/manuela/",
	"刘娅希":         "https://www.mzitu.com/tag/liuyaxi/",
	"嘉宝贝儿":        "https://www.mzitu.com/tag/jiabaobei/",
	"luvian本能":    "https://www.mzitu.com/tag/luvian/",
	"张优":          "https://www.mzitu.com/tag/zhangyou/",
	"于姬una":       "https://www.mzitu.com/tag/yuji-una/",
	"岸明日香":        "https://www.mzitu.com/tag/hanmingrixiang/",
	"筱崎爱":         "https://www.mzitu.com/tag/xiaoqiai/",
	"吉木梨纱":        "https://www.mzitu.com/tag/jimulisha/",
	"李七喜":         "https://www.mzitu.com/tag/liqixi/",
	"陈思琪art":      "https://www.mzitu.com/tag/chensiqi/",
	"杨依":          "https://www.mzitu.com/tag/yangyi/",
	"王雨纯":         "https://www.mzitu.com/tag/wangyuchun/",
	"诗朵雅":         "https://www.mzitu.com/tag/shiduoya/",
	"沫晓伊baby":     "https://www.mzitu.com/tag/moxiaoyi/",
	"喜屋武千秋":       "https://www.mzitu.com/tag/xiwuwuqianqiu/",
	"陆瓷":          "https://www.mzitu.com/tag/luchi/",
	"子纯儿annie":    "https://www.mzitu.com/tag/zhichuner-annie/",
	"诗诗sissi":     "https://www.mzitu.com/tag/xiuren-sisi/",
	"郭婉祈":         "https://www.mzitu.com/tag/guowanqi/",
	"孟狐狸foxyini":  "https://www.mzitu.com/tag/foxyini/",
	"米妮大萌萌":       "https://www.mzitu.com/tag/minida/",
	"亚里沙":         "https://www.mzitu.com/tag/yalisha/",
	"瑞莎Trista":    "https://www.mzitu.com/tag/ruisha/",
	"佟蔓":          "https://www.mzitu.com/tag/tongman/",
	"张栩菲":         "https://www.mzitu.com/tag/zhangxufei/",
	"Milk楚楚":      "https://www.mzitu.com/tag/milk-chuchu/",
	"陈怡曼":         "https://www.mzitu.com/tag/chenyiman/",
	"徐cake":       "https://www.mzitu.com/tag/xu-cake/",
	"松果儿":         "https://www.mzitu.com/tag/songguoer/",
	"夏美酱":         "https://www.mzitu.com/tag/xiameijiang/",
	"乐乐Mango":     "https://www.mzitu.com/tag/lele-mango/",
	"纯小希":         "https://www.mzitu.com/tag/chunxiaoxi/",
	"闵妮Mily":      "https://www.mzitu.com/tag/minni-mily/",
	"熊吖BOBO":      "https://www.mzitu.com/tag/bobo/",
	"赵小米":         "https://www.mzitu.com/tag/zhaoxiaomi/",
	"梓萱Crystal":   "https://www.mzitu.com/tag/zixuan-crystal/",
	"叶佳颐":         "https://www.mzitu.com/tag/yejiayi/",
	"尤美Yumi":      "https://www.mzitu.com/tag/youmei-ann/",
	"沈佳熹":         "https://www.mzitu.com/tag/shenjiaxi/",
	"田熙玥":         "https://www.mzitu.com/tag/tianxiyue/",
	"宋梓诺":         "https://www.mzitu.com/tag/songzinuo/",
	"沈蜜桃":         "https://www.mzitu.com/tag/shenmitao/",
	"Cheryl青树":    "https://www.mzitu.com/tag/cheryl-qingshu/",
	"思淇Sukiii":    "https://www.mzitu.com/tag/siqi-sukiii/",
	"琳琳ailin":     "https://www.mzitu.com/tag/linlin-ailin/",
	"陈思雨":         "https://www.mzitu.com/tag/chensiyu/",
	"伊小七":         "https://www.mzitu.com/tag/yixiaoqi-momo/",
	"沈梦瑶":         "https://www.mzitu.com/tag/shenmengyao/",
	"杨晨晨":         "https://www.mzitu.com/tag/xiaotianxin-gugar/",
	"猩一":          "https://www.mzitu.com/tag/xingyi/",
	"绯月樱":         "https://www.mzitu.com/tag/xiezhixin/",
	"丁筱南":         "https://www.mzitu.com/tag/dingxiaonian/",
	"嘉琳winna":     "https://www.mzitu.com/tag/jialin-winna/",
	"赵伊彤":         "https://www.mzitu.com/tag/zhaoyitong/",
	"韩恩熙":         "https://www.mzitu.com/tag/hanenxi/",
	"唐雨辰":         "https://www.mzitu.com/tag/tangyuchen/",
	"慕羽茜":         "https://www.mzitu.com/tag/muyuqian/",
	"柳侑绮":         "https://www.mzitu.com/tag/liuyouqi/",
	"邹晶晶":         "https://www.mzitu.com/tag/zoujingjing/",
	"唐琪儿":         "https://www.mzitu.com/tag/tangqier-beauty/",
	"萌萌Vivian":    "https://www.mzitu.com/tag/mengmeng-vivian/",
	"萌琪琪":         "https://www.mzitu.com/tag/mengqiqi/",
	"张美荧":         "https://www.mzitu.com/tag/zhangmeiying/",
	"土肥圆矮挫穷":      "https://www.mzitu.com/tag/tufeiyuanai/",
	"晓茜sunny":     "https://www.mzitu.com/tag/xiaoqian-sunny/",
	"刘钰儿":         "https://www.mzitu.com/tag/liuyuer/",
	"李梓熙":         "https://www.mzitu.com/tag/lizixi/",
	"刘奕宁":         "https://www.mzitu.com/tag/liuyining/",
	"凯竹BuiBui":    "https://www.mzitu.com/tag/kaizhu-buibui/",
	"Sukki":       "https://www.mzitu.com/tag/sukki/",
	"穆菲菲":         "https://www.mzitu.com/tag/mufeifei/",
	"Egg尤妮丝":      "https://www.mzitu.com/tag/egg-younisi/",
	"妲己Toxic":     "https://www.mzitu.com/tag/daji-toxic/",
	"SOLO尹菲":      "https://www.mzitu.com/tag/solo-yifei/",
	"王婉悠":         "https://www.mzitu.com/tag/wangwanyou/",
	"筱慧icon":      "https://www.mzitu.com/tag/xiaohui/",
	"廿十":          "https://www.mzitu.com/tag/nianshi/",
	"Evelyn艾莉":    "https://www.mzitu.com/tag/evelyn-aili/",
	"爱丽莎":         "https://www.mzitu.com/tag/ailisha/",
	"雪千寻":         "https://www.mzitu.com/tag/xueqianxun/",
	"芝芝Booty":     "https://www.mzitu.com/tag/zhizhi-booty/",
	"易阳":          "https://www.mzitu.com/tag/yiyang/",
	"月音瞳":         "https://www.mzitu.com/tag/yueyintong/",
	"顾灿":          "https://www.mzitu.com/tag/gucan/",
	"蔡文钰":         "https://www.mzitu.com/tag/caiwenyu-angle/",
	"黄歆苑":         "https://www.mzitu.com/tag/huangxinyuan/",
	"丹丹":          "https://www.mzitu.com/tag/dandan/",
	"米雪":          "https://www.mzitu.com/tag/mixue/",
	"周于希":         "https://www.mzitu.com/tag/zhouyuxi-dummy/",
	"黄楽然":         "https://www.mzitu.com/tag/huangleran/",
	"恩一":          "https://www.mzitu.com/tag/enyi/",
	"夏笑笑":         "https://www.mzitu.com/tag/xiaoxiao/",
	"李可可":         "https://www.mzitu.com/tag/likeke/",
	"M梦Baby":      "https://www.mzitu.com/tag/meng-baby/",
	"艾小青":         "https://www.mzitu.com/tag/aixiaoqing/",
	"何晨曦":         "https://www.mzitu.com/tag/hechenxi/",
	"温心怡":         "https://www.mzitu.com/tag/wenxinyi/",
	"徐微微":         "https://www.mzitu.com/tag/xuweiwei_mia/",
	"卓娅祺":         "https://www.mzitu.com/tag/zhuoyaqi/",
	"卤蛋luna":      "https://www.mzitu.com/tag/ludan-luna/",
	"陆梓琪":         "https://www.mzitu.com/tag/luziqi/",
	"宅兔兔":         "https://www.mzitu.com/tag/zhaitutu/",
	"心妍小公主":       "https://www.mzitu.com/tag/xinyanxiaogongzhu/",
	"龍籹cool":      "https://www.mzitu.com/tag/panpanlongnv-sunny/",
	"考拉koala":     "https://www.mzitu.com/tag/kaola-koala/",
	"萌汉药baby":     "https://www.mzitu.com/tag/menghanyao-baby/",
	"宋Ki":         "https://www.mzitu.com/tag/song-kiki/",
	"小狐狸Sica":     "https://www.mzitu.com/tag/xiaohuli-sica/",
	"孙梦瑶":         "https://www.mzitu.com/tag/sunmengyao/",
	"Wendy智秀":     "https://www.mzitu.com/tag/wendy-zhixiu/",
	"王梓童":         "https://www.mzitu.com/tag/wangzitong-doirs/",
	"小热巴":         "https://www.mzitu.com/tag/xiaoreba/",
	"乔依琳":         "https://www.mzitu.com/tag/qiaoyilin/",
	"唐思琪":         "https://www.mzitu.com/tag/tangsiqi/",
	"娜露Selena":    "https://www.mzitu.com/tag/selena/",
	"艾栗栗":         "https://www.mzitu.com/tag/ailili/",
	"小尤奈":         "https://www.mzitu.com/tag/xiaoyounai/",
	"冯木木":         "https://www.mzitu.com/tag/fengmumu-lris/",
	"李宓儿":         "https://www.mzitu.com/tag/limier/",
	"林美惠子":        "https://www.mzitu.com/tag/leimeihuizi/",
	"嘉嘉Tiffany":   "https://www.mzitu.com/tag/jiajia-tiffany/",
	"小九月":         "https://www.mzitu.com/tag/xiaojiuyue/",
	"唐婉儿":         "https://www.mzitu.com/tag/tangwaner/",
	"栗子Riz":       "https://www.mzitu.com/tag/lizi-riz/",
	"张雨萌":         "https://www.mzitu.com/tag/zhangyumeng/",
	"杜花花":         "https://www.mzitu.com/tag/duhuahua/",
	"Miko酱":       "https://www.mzitu.com/tag/miko-jiang/",
	"瑞瑞ruirui":    "https://www.mzitu.com/tag/ruirui/",
	"楚恬Olivia":    "https://www.mzitu.com/tag/chutian_olivia/",
	"杨漫妮":         "https://www.mzitu.com/tag/yangmanni/",
	"何嘉颖":         "https://www.mzitu.com/tag/hejiaying/",
	"Carry":       "https://www.mzitu.com/tag/carry/",
	"Miki兔":       "https://www.mzitu.com/tag/miki-tu/",
	"梦心月":         "https://www.mzitu.com/tag/mengxinyue/",
	"艺轩":          "https://www.mzitu.com/tag/yixuan/",
	"就是阿朱啊":       "https://www.mzitu.com/tag/azhu/",
	"潘琳琳":         "https://www.mzitu.com/tag/panlinlin/",
	"仓井优香":        "https://www.mzitu.com/tag/cangjingyouxiang/",
	"糯美子":         "https://www.mzitu.com/tag/nuomeizi/",
	"陶喜乐":         "https://www.mzitu.com/tag/taoxile/",
	"陆萱萱":         "https://www.mzitu.com/tag/luxuanxuan/",
	"任莹樱":         "https://www.mzitu.com/tag/jennanni_jen/",
	"林子欣":         "https://www.mzitu.com/tag/linzixin/",
	"夏诗诗":         "https://www.mzitu.com/tag/xiashishi/",
	"诗诗KIKI":      "https://www.mzitu.com/tag/sisi-kiki/",
	"玉兔miki":      "https://www.mzitu.com/tag/yutu-miki/",
	"陈小喵":         "https://www.mzitu.com/tag/chenxiaomiao/",
	"徐安安":         "https://www.mzitu.com/tag/xuanan/",
	"安然Maleah":    "https://www.mzitu.com/tag/anran-maleah/",
	"夏小雅":         "https://www.mzitu.com/tag/xiaxiaoya/",
	"杨紫嫣":         "https://www.mzitu.com/tag/yangziyan/",
	"软软Roro":      "https://www.mzitu.com/tag/ruanruan-roro/",
	"周思乔":         "https://www.mzitu.com/tag/zhousiqiao/",
	"久久Aimee":     "https://www.mzitu.com/tag/jiujiu-aimee/",
}

func GetImageUrl(href string) (imgUrl string, err error) {
	d, err := RequestUrl(href)
	if err != nil {
		return
	}
	maxPage := 1
	d.Find("div.pagination .page-numbers").Contents().Each(func(i int, s *goquery.Selection) {
		page, err := strconv.Atoi(s.Text())
		if err != nil {
			return
		}
		if page > maxPage {
			maxPage = page
		}
	})
	page := rand.Intn(maxPage)
	d, err = RequestUrl(fmt.Sprintf("%spage/%d/", href, page))
	if err != nil {
		return
	}
	liDom := d.Find("#pins li")
	randint := rand.Intn(liDom.Length())
	liDom.Each(func(i int, s *goquery.Selection) {
		dd, exists := s.Find("a").Attr("href")
		if i == randint && exists {
			dddImg, err := RequestUrl(dd)
			if err != nil {
				return
			}
			maxPage := 1
			dddImg.Find(".pagenavi span").Contents().Each(func(i int, s *goquery.Selection) {
				page, err := strconv.Atoi(s.Text())
				if err != nil {
					return
				}
				if page > maxPage {
					maxPage = page
				}
			})
			page = rand.Intn(maxPage)
			dddImg, err = RequestUrl(fmt.Sprintf("%s/%d", dd, page))
			if err != nil {
				return
			}
			ImgSrc, exists := dddImg.Find(".main-image img").Attr("src")
			if exists {
				imgUrl = ImgSrc
			}
		}
	})
	return
}

func GetImage() (imgUrl string, err error) {
	imgUrl = "https://3650000.xyz/api/"
	// l := GetLabelList(1)
	// for _, v := range l {
	// 	s := GetLabel(v)
	// 	if s != "" {
	// 		imgUrl, err = GetImageUrl(s)
	// 	}
	// }
	return
}

func GetLabel(label string) (url string) {
	url = lists[label]
	return
}

func GetLabelList(max int) (l []string) {
	for key := range lists {
		l = append(l, key)
	}
	l = l[:max]
	return
}
